﻿/************************************\
 *   ___                            *
 *  /                          /    *
 * (___ |  ___  ___       ___ (___  *
 * |    | |   )|___)| / )|___)|   ) *
 * |    | |    |__  |/|/ |__  |__/  *
 *                                  *
 * FireWeb - C# OpenSource Browser  *
\************************************/
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
using System.Management;

namespace FireWeb.Pages
{
    public partial class TabManager : Form
    {
        private int MainPID;
        public TabManager(int _MainPID)
        {
            InitializeComponent();
            MainPID = _MainPID;
            Refresh();
        }

        void AddProcessToList(int PID)
        {
            foreach (ListViewItem Item in ProcessesList.Items)
            {
                Item.Remove();
            }

            Process TabProcess = Process.GetProcessById(PID);
            ProcessesList.Items.Add("Tab: " + TabProcess.MainWindowTitle).SubItems.AddRange(new string[] { TabProcess.PrivateMemorySize64 / 1024 + "K", TabProcess.PrivilegedProcessorTime + "%", "0%" });
        }

        void Refresh()
        {
            ManagementObjectSearcher Search = new ManagementObjectSearcher("Select * From Win32_Process Where ParentProcessID=" + MainPID);
            ManagementObjectCollection Objects = Search.Get();

            foreach (ManagementObject Object in Objects)
            {
                AddProcessToList(Convert.ToInt32(Object["ProcessID"]));
            }
        }

        private void RefreshTimer_Tick(object sender, EventArgs e)
        {
            Refresh();
        }
    }
}
